package edu.ahpu.propertymanage.util;

import edu.ahpu.propertymanage.pojo.PropertyTage;
import edu.ahpu.propertymanage.service.PropertyTageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

@Component
public class GetID {

    @Autowired
    PropertyTageService propertyTageService;

    public String createManagerUUID() {
        PropertyTage tage = propertyTageService.getById(1);
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
        String id = tage.getTage() + "-M-" + uuid;
        return id;
    }

    public String createVisitorUUID() {
        PropertyTage tage = propertyTageService.getById(1);
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
        String id = tage.getTage() + "-V-" + uuid;
        return id;
    }

    public String createWorkerUUID() {
        PropertyTage tage = propertyTageService.getById(1);
        String uuid = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
        String id = tage.getTage() + "-W-" + uuid;
        return id;
    }

    public String createOwnerUUID(String area, int dong, int unit, int room) {
        PropertyTage tage = propertyTageService.getById(1);
        String id = tage.getTage() + "-O-" + area + dong + unit + room;
        return id;
    }

    public String createMessageID() {
        PropertyTage propertyTage = propertyTageService.getById(1);
        String id = propertyTage.getTage() + "-MSG-";

        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhMMss");
        Date date = new Date();
        String str = sdf.format(date);
        System.out.println(str);
//        str = str.substring(0,8);
        id = id + str;
        return id;
    }

    public String getProjectId() {
        PropertyTage propertyTage = propertyTageService.getById(1);
        String id = propertyTage.getTage() + "-P-";
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhMMss");
        Date date = new Date();
        String str = sdf.format(date);
        id = id +str;
        return id;
    }

    public String getDispatchId(){
        PropertyTage propertyTage = propertyTageService.getById(1);
        String id = propertyTage.getTage() + "-D-";
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhMMss");
        Date date = new Date();
        String str = sdf.format(date);
        id = id +str;
        return id;
    }

    public String getSecurityId(){
        PropertyTage propertyTage = propertyTageService.getById(1);
        String id = propertyTage.getTage() + "-S-";
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhMMss");
        Date date = new Date();
        String str = sdf.format(date);
        id = id +str;
        return id;
    }

    public String getRepairId(){
        PropertyTage propertyTage = propertyTageService.getById(1);
        String id = propertyTage.getTage() + "-R-";
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddhhMMss");
        Date date = new Date();
        String str = sdf.format(date);
        id = id +str;
        return id;
    }

    public String getSms(){
        String code = UUID.randomUUID().toString().toUpperCase().replace("-","").substring(5,10);

        return code;
    }


}
